# - Coding UTF8 -
#
# Networked Decision Making
# Site: http://code.google.com/p/global-decision-making-system/
#
# License Code: GPL, General Public License v. 2.0
# License Content: Creative Commons Attribution 3.0
#
# Also visit: www.web2py.com
#             or Groups: http://groups.google.com/group/web2py 
# 	For details on the web framework used for this development
#
# Developed by Russ King (newglobalstrategy@gmail.com
# Russ also blogs occasionally to pass the time at: 
# http://proudofyourplanent.blogspot.com
# His general thinking on why this project is very important is available at
# http://www.scribd.com/doc/98216626/New-Global-Strategy
# With thanks to Guido, Massimo and many other that make this sort of thing
# much easier than it used to be

#This adds std questions and actionsto the database - only run this if you are 
#looking to test a std system or have some desire to reperform the demo questions in a different environment

@auth.requires_membership('manager')
def stdquest():
    txt1=r"Should we develop a global strategy as outlined at: http://www.ted.com/talks/jamie_drummond_how_to_set_goals_for_the_world.html ?"
    if db(db.question.questiontext == txt1).isempty():
        q1 = db.question.insert(qtype="quest", questiontext=txt1, auth_userid = auth.user.id, numanswers=2,answers=["Yes","No"],urgency=6,importance=8,priority=48, category='Strategy')

    txt2="Is it possible to live for more than 120 years?"
    if db(db.question.questiontext == txt2).isempty():
        q2 = db.question.insert(qtype="quest", questiontext=txt2, auth_userid = auth.user.id, numanswers=2,answers=["Yes","No"],urgency=4,importance=6,priority=24, category='Healthcare' )

    txt2a="Do we know if nothing is a stable state?"
    if db(db.question.questiontext == txt2a).isempty():
        q2 = db.question.insert(qtype="quest", questiontext=txt2a, auth_userid = auth.user.id, numanswers=3,answers=["Yes","No","We don't know we just assume it is"],
        urgency=3,importance=6, category='Philosophy')

    txt3="Is it reasonable to try and promote biogerontology research?"
    if db(db.question.questiontext ==txt3).isempty():
        q3 = db.question.insert(qtype="quest", questiontext=txt3, auth_userid = auth.user.id, numanswers=2,answers=["Yes","No"],urgency=6,importance=6,priority=36)

    txt4="Are we underachieving what might be possible if we worked together?"
    if db(db.question.questiontext ==txt4).isempty():
        q4 = db.question.insert(qtype="quest", questiontext=txt4, auth_userid = auth.user.id, numanswers=2,answers=["Yes","No"],urgency=7,importance=7,priority=49, category='Strategy')

    txt5="Is there sufficient education on when to compete and when to co-operate?"
    if db(db.question.questiontext == txt5).isempty():
        q5 = db.question.insert(qtype="quest", questiontext=txt5, auth_userid = auth.user.id, numanswers=2,answers=["Yes","No"],urgency=4,importance=8,priority=32,category='Strategy' )
        db(db.question.id == q5).update(subsquests=q1)
        db(db.question.id == q1).update(priorquests=q5)

    txt6="Are you aware of the global strategy?"
    if db(db.question.questiontext == txt6).isempty():
        q6 = db.question.insert(qtype="quest", questiontext=txt6, auth_userid = auth.user.id, numanswers=2,answers=["Yes","No"])

    txt7="Did you choose where you were born?"
    if db(db.question.questiontext ==txt7).isempty():
        q7 = db.question.insert(qtype="quest", questiontext=txt7, auth_userid = auth.user.id, numanswers=2,answers=["Yes","No"],urgency=4,importance=4,priority=16,category='Philosophy')

    txt8="Is it right that place of birth determines so much of your life and restricts so many people?"
    if db(db.question.questiontext ==txt8).isempty():
        q8 = db.question.insert(qtype="quest", questiontext=txt8, auth_userid = auth.user.id, numanswers=2,answers=["Yes","No"],urgency=4,importance=7,priority=28, category='Philosophy' )
        db(db.question.id == q7).update(subsquests=q8)
        db(db.question.id == q8).update(priorquests=q7)

    txt9="Do we need to localise decision making?"
    if db(db.question.questiontext ==txt9).isempty():
        q9 = db.question.insert(qtype="quest", questiontext=txt9, auth_userid = auth.user.id, numanswers=2,answers=["Yes","No"],urgency=6,importance=8,priority=48,category='Organisation')

    txt10="Could we unite theists and atheists on a project to create heaven on earth?"
    if db(db.question.questiontext == txt10).isempty():
        q10 = db.question.insert(qtype="quest", questiontext=txt10, auth_userid = auth.user.id, numanswers=2,answers=["Yes","No"],urgency=7,importance=8,priority=56,category='Philosophy')


    txt11="What is the optimum number of countries in the world?"
    if db(db.question.questiontext ==txt11).isempty():
        q11 = db.question.insert(qtype="quest", questiontext=txt11, auth_userid = auth.user.id, numanswers=4,answers=["Just right", "Too many","Too few","One"],urgency=6,importance=8,priority=48,  category='Philosophy')

    txt12="Is space tourism a sensible use of resources at present?"
    if db(db.question.questiontext == txt12).isempty():
        q12 = db.question.insert(qtype="quest", questiontext=txt12, auth_userid = auth.user.id, numanswers=2,answers=["Yes","No"],urgency=6,importance=8,priority=48, category='Organisation')

    txt13="What are the best solutions to work on right now?"
    if db(db.question.questiontext == txt13).isempty():
        q13 = db.question.insert(qtype="quest", questiontext=txt13, auth_userid = auth.user.id, numanswers=5,answers=["Prevention of HIV/Aids", "Networked Decision Making","Malaria","Malnutrition","Global Warming"],urgency=8,importance=8,priority=64, category='Strategy')

    txt14="Is the world under-achieving?"
    if db(db.question.questiontext == txt14).isempty():
        q14 = db.question.insert(qtype="quest", questiontext=txt14, auth_userid = auth.user.id, numanswers=2,answers=["Yes","No"],category='Organisation' )

    txt15="What is the main problem with the world right now?"
    if db(db.question.questiontext == txt15).isempty():
        q15 = db.question.insert(qtype="quest", questiontext=txt15, auth_userid = auth.user.id, numanswers=6, answers=["There is no problem - everything is perfect","There simply isn't enough food in the world so some people have to starve","Many people don't care if other people are starving","Humans lack the skills to organise the planet","Humans derive pleasure from having more than other people","Lack of vision to see that creating alignment on objectives will get us all much better futures and longer and happier lives"], urgency=7,importance=8,priority=56, category='Organisation')

    if db(db.question.questiontext =="Does God Exist?").isempty():
        q16 = db.question.insert(qtype="quest", questiontext="Does God Exist?", auth_userid = auth.user.id, numanswers=2, answers=['Yes','No'],urgency=4,importance=7,priority=28, category='Philosophy')

    q17 = None

    if db(db.question.questiontext =="Is God rational?").isempty():
        q17 = db.question.insert(qtype="quest", questiontext="Is God rational?", auth_userid = auth.user.id, numanswers=2,answers=["Yes","No"],urgency=5,importance=7,priority=35,category='Philosophy')
    
    txt18="Is it rational to believe in an irrational God?"
    if db(db.question.questiontext == txt18).isempty():
        q18 = db.question.insert(qtype="quest", questiontext=txt18, auth_userid = auth.user.id, numanswers=2,answers=["Yes","No"],urgency=6,importance=7,priority=42, category='Philosophy')
        if q17:
            db(db.question.id == q17).update(subsquests=q18)
            db(db.question.id == q18).update(priorquests=q17)

    txt19="Is aging a disease or is it just inevitable and we should accept it?"
    if db(db.question.questiontext == txt19).isempty():
        q19 = db.question.insert(qtype="quest", questiontext=txt19, auth_userid = auth.user.id, numanswers=2,answers=["A disease","Inevitable"], urgency=4,importance=7,priority=28, category='Healthcare')

    txt20="Do countries assist or hinder the operation of the world?"
    if db(db.question.questiontext == txt20).isempty():
        q20 = db.question.insert(qtype="quest", questiontext=txt20, auth_userid = auth.user.id, numanswers=2,answers=["Assist","Hinder"], urgency=6,importance=7,priority=42, category='Organisation')

    txt21="Why are so many people unemployed?"   
    if db(db.question.questiontext == txt21).isempty():
        q21 = db.question.insert(qtype="quest", questiontext=txt21, auth_userid = auth.user.id, numanswers=5,answers=["The unemployed are all useless", "Just a cost of human progress that many are left with lots of leisure but little income","Inability to co-operate, share and work together","Many people are just lazy","Something else"], urgency=8,importance=7,priority=56,category='Organisation')

    txt22=r"Did JFK speed-up or slow down progress in getting to the moon by explaining that was the intention in 1962  http://www.astrosociology.com/Library/PDF/JFK%201962%20Rice%20University%20Speech%20Transcript.pdf ?"
    if db(db.question.questiontext ==txt22).isempty():
        q22 = db.question.insert(qtype="quest", questiontext=txt22, auth_userid = auth.user.id, numanswers=2,answers=["Speed Up", "Slow down"], urgency=7,importance=7,priority=49, category='Organisation')

    txt23="If stating we were going to the moon was important to getting there is there not a similarly strong case for saying we are going to extend human lifespans' ?"
    if db(db.question.questiontext == txt23).isempty():
        q23 = db.question.insert(qtype="quest", questiontext=txt23, auth_userid = auth.user.id, numanswers=2,answers=["Yes","No"], urgency=6,importance=9,priority=54,category='Organisation')
        db(db.question.id == q22).update(subsquests=q23)
        db(db.question.id == q23).update(priorquests=q22)

    txt24="Should Scotland become an independent country?"
    if db(db.question.questiontext == txt24).isempty():
        q24 = db.question.insert(qtype="quest", questiontext=txt24, auth_userid = auth.user.id, numanswers=2,
        answers=["Yes","No"] ,urgency=4,importance=7,priority=28,category='Organisation',continent='Europe (EU)',
        country='United Kingdom (EU)',activescope='3 National')
        db(db.question.id == q24).update(scopetext = 'United Kingdom (EU)')

    txt25="Should we develop social network integration features for networked decision making?"
    if db(db.question.questiontext ==txt25).isempty():
        q25 = db.question.insert(qtype="quest", questiontext=txt25, auth_userid = auth.user.id, numanswers=2,answers=["Yes","No"],urgency=4,importance=7, category='Net Decision Making')

    txt26="Which social networking platform should be developed first?"
    if db(db.question.questiontext == txt26).isempty():
        q26 = db.question.insert(qtype="quest", questiontext=txt26, auth_userid = auth.user.id, numanswers=4,answers=["Facebook","Twitter","Google+","Other"],urgency=4,importance=7,category='Net Decision Making')
        db(db.question.id == q25).update(subsquests=q26)
        db(db.question.id == q26).update(priorquests=q25)

    txt27="Should we look to use advertising to fund the running costs of NDS?"
    if db(db.question.questiontext == txt27).isempty():
        q27 = db.question.insert(qtype="quest", questiontext=txt27, auth_userid = auth.user.id, numanswers=2,answers=["Yes","No"],urgency=4,importance=7,priority=28,category='Net Decision Making')

    txt28="Is the United States a corruption as alleged at http://www.ted.com/talks/lawrence_lessig_we_the_people_and_the_republic_we_must_reclaim.html ?"
    if db(db.question.questiontext ==txt28).isempty():
        q28 = db.question.insert(qtype="quest", questiontext=txt28, auth_userid = auth.user.id, numanswers=2,answers=["Yes","No"],urgency=4,importance=7,priority=28,category='Organisation',
        continent='North America (NA)',country='United States (NA)',activescope='3 National')
        db(db.question.id == q28).update(scopetext = 'United States (NA)')

    txt29="The distribution of wealth on the planet is radically different thant that predicted by micro-economic theory.  The question therefore arises does acquisition of great wealth require exploitation of others?"
    if db(db.question.questiontext == txt29).isempty():
        q29 = db.question.insert(qtype="quest", questiontext=txt29, auth_userid = auth.user.id, numanswers=3,answers=["Yes","No","Usually"], urgency=4,importance=4)

    act1=r"The top priority action from the 2012 Copenhagen Consensus (http://copenhagenconsensus.com) to use bundled micronutrient interventions to fight hunger and improve education should be actioned and funded by a $75bn cut to US defence spending"
    if db(db.question.questiontext == act1).isempty():
        a1=db.question.insert(qtype="action", questiontext=act1, auth_userid = auth.user.id, numanswers=2,
        answers=["Approve","Disapprove","OK"],urgency=8,importance=9,responsible='Barrack Obama', category='Food')
        db(db.question.id == q13).update(subsquests=a1)
        db(db.question.id == a1).update(priorquests=q13)

    act2="Unless they have already done so, all global citizens with net assets in excess of US$100 million should invest 1% of their assets in biogerontology or related research and action. Eg The Gates Foundation activities and Ellison medical would both count so several leading individuals have done this already."
    if db(db.question.questiontext == act2).isempty():
        a2=db.question.insert(qtype="action", questiontext=act2, auth_userid = auth.user.id, numanswers=2,
        answers=["Approve","Disapprove","OK"],urgency=8,importance=8,responsible='people with >$100M',category='Healthcare')


    act3= "Daylight saving time should operate all year in Europe to reduce accidents and CO2 emissions"
    if db(db.question.questiontext == act3).isempty():
        a3=db.question.insert(qtype="action", questiontext=act3, auth_userid = auth.user.id, numanswers=2,answers=["Approve","Disapprove","OK"],urgency=6,importance=6,responsible='Jose Manuel Barroso',category='Organisation',continent='Europe (EU)',activescope='2 Continental')
        db(db.question.id == a3).update(scopetext = 'Europe (EU)')

    
    act4="The funding model for US politics must change"
    if db(db.question.questiontext == act4).isempty():
        a4=db.question.insert(qtype="action", questiontext=act4, auth_userid = auth.user.id,
        numanswers=2,answers=["Approve","Disapprove","OK"],urgency=5,importance=8,
        responsible='Barrack Obama',category='Organisation',continent='North America (NA)',
        country='United States (NA)',activescope='3 National')
        db(db.question.id == q28).update(subsquests=a4)
        db(db.question.id == a4).update(priorquests=q28)
        db(db.question.id == a4).update(scopetext = 'United States (NA)')

    act5="All African health centres and schools should get internet access to improve access and trust in the global knowledge base, this should be provided by leading pharmaceutical and technology companies working together"
    if db(db.question.questiontext == act5).isempty():
        a5=db.question.insert(qtype="action", questiontext=act5, auth_userid = auth.user.id,
        numanswers=2,answers=["Approve","Disapprove","OK"],urgency=5,importance=8
        ,responsible='CEOs of leading pharma & IT Companies',category='Organisation',
        continent='Africa (AF)',activescope='2 Continental')
        db(db.question.id == a5).update(scopetext = 'Africa')

    act6="A national solution to the problem of misfuelling cars with petrol instead of diesel should be establised in the UK the costs of this problem are  estimated at around $120M per year and magnets, RFID readers on fuel pumps, better fuel caps or some other agreed approach should be able to permanently eliminate this waste for less than half that cost"
    if db(db.question.questiontext == act6).isempty():
        a6=db.question.insert(qtype="action", questiontext=act6, auth_userid = auth.user.id,
        numanswers=2,answers=["Approve","Disapprove","OK"],urgency=5,importance=6,
        responsible='CEOs of leading Auto & Oil Companies',category='Organisation', continent='Europe (EU)',
        country='United Kingdom (EU)',activescope='3 National')
        db(db.question.id == a6).update(scopetext = 'United Kingdom (EU)')


    act7="The programme to deliver better housing as explained at http://www.ted.com/talks/paul_pholeros_how_to_reduce_poverty_fix_homes.html should be rolled out globally with associated crowdsourced measurement of progress. "
    if db(db.question.questiontext == act7).isempty():
        a6=db.question.insert(qtype="action", questiontext=act7, auth_userid = auth.user.id,
        numanswers=2,answers=["Approve","Disapprove","OK"],urgency=7,importance=7,
        responsible='All global leaders',category='Sanitation')


    act8="Google should develop a globally scaleable version of the network decision making system outlined here"
    if db(db.question.questiontext == act8).isempty():
        a6=db.question.insert(qtype="action", questiontext=act8, auth_userid = auth.user.id,
        numanswers=2,answers=["Approve","Disapprove","OK"],urgency=7,importance=7,
        responsible='Eric Schmidt',category='Net Decision Making')
    return locals()


#Not now using this question - but left in as may do in future and it remains worthy of consideration
@auth.requires_membership('manager')
def longquest():
    txt1='''#Problem 

Imagine a planet with two people(X and Y) and many things fully automated so it is largely a service and knowledge economy.  There are two full-time jobs requiring each person to do some work for the other. \n


Both jobs are open at the start and the planet is fair. To avoid stagnation the jobs will be re-advertised and applied for each period.  There is a concern that both jobs paying the same provides little incentive to work hard and secure the better job.  It seems better to have one good job and one perfectly acceptable but not quite so good job.  All changes are consensual and must be agreed by both – however if there is a disagreement the holder of the good job gets the casting vote.\n

Initially, wealth on the planet is shared equally and both are equally and highly talented so neither is better suited to the better job.  Being fair and reasonable but recognising that necessary job skills will be acquired through practice they flip a coin to assign the jobs.  X wins the flip and gets the better job.   This is a stable small planet and both jobs require the same amount of capital so they agree that each will own the assets required for their jobs.  As a further simplification we assume that capital equipment is permanent and there is no requirement for investment to support innovation and there is no bank.\n



Y is disappointed at losing the flip but it was fair and agreed up front and his job is OK.  The planet operates like earth, except there are no taxes.  Consequently one person’s expenditure must equal the other person’s income.  Income allows spending at the various automated services and vending machines on the planet and is collected by the other and they are required to spend sufficient to pay the others wages.\n 

The time comes for re-advertising the jobs.  While it might seem fairest to swap jobs, X points out that they are now both experienced and better able to do their jobs so it makes sense to continue with the current division of labour.  Y accepts this is true but is unhappy that they will be making less than X.  Both are quicker at their tasks through practice and seeing improvement opportunities.  More time passes and both continue to learn and make improvements. Each year there is also a transfer of wealth from Y to X because X can ensure his expenditure never exceeds his income.\n 



At the first period end it was just noted that Y owed X for the difference between their incomes.  However as debt builds up over time X insists that Y sell some of his assets to X and X decides that it’s now appropriate to charge rent on the assets he owns that Y uses.  As X possesses the good job Y has to agree.  This situation remains unstable as Y will end up with no assets and X will own everything.  Recognising this will happen and being farsighted and firmly in a leadership role now X decides that some of his job is rather tedious so Y can now work longer than X to allow him to pay the rent.\n



This is annoying for Y as they started equal but progress continues and while Y is seeing less opportunities X is continuing to find ways to improve work.  There is now much less than two full time jobs – however Y still works full-time and X works less and less.\n

‘Equilibrium’ arises once X owns 100% of the assets and does no work.  In practice X doesn’t completely trust Y so still does some work and has concerns that if he is unreasonable Y may rebel.   X is often comfortable with about 90% of the wealth and doing 10% of the work.  X finds time for charitable causes.\n 



X likes to be seen to be doing some work.  They’ve earned everything having got a good job all these years earlier and improving continuously at a good rate whereas Y stalled for some reason.  Everything that happened seems quite fair, reasonable and agreeable – yes he had a little bit of luck at the start – but that didn’t even merit mention in his memoirs.  Y is not happy with the arrangements but nothing legal could be done about it – those were the rules on this new fairer planet.  At times Y is happier than X as being fully employed provides a sense of purpose.  The situation could just as easily have been reversed if Y had been lucky. \n

The above partly depicts why you get heavily concentrated wealth on your planet.  Similar arrangements have proved predictable and unchanging over centuries with wealthy families cleverly following the Micawber principal.  Y may be equally familiar and keen on the principal but the rules of mathematics make it impossible for him to comply with it.  However when X is idle and Y is fully occupied the results that Micawber predicted don’t always arise.  Y may actually be happier than X.\n


Wealth distribution is a taboo topic in economics so let’s consider progress instead.  X is typically highly educated, capable and with some experience of working in their earlier years but at some point they determine they have enough and start to focus on playing golf or whatever.  Y typically feels exploited and demotivation is probable.  Neither is fully committed to progress and at economic equilibrium there will probably be zero growth as if X isn’t working at all then he won’t be improving productivity and Y will be conditioned that improvements just result in substitution of other duties to fill the time.  X may well consider there is no problem.  Equilibrium however arises at less than 50% of theoretical capacity as X does nothing and Y isn’t motivated to make improvements.\n

The above arrangements will remain stable until X agrees to change it.  That will only happen if X decides making progress quicker is important.  At that point they will re-engage with work and may also decide to incentivise Y. 


This may not happen while progress consists of larger televisions or smarter smartphones.  If however progress is a cure for a disease X is suffering from then the focus will be greater.  In the case of humans, aging is a degenerative disease that you all suffer from in time.  It does seem quite reasonable that within the next 50 years the effects can be delayed, perhaps by 20 or 30 years.  As has been pointed out if that happens then it creates another 20 to 30 years of development on further slowing or reversing the effects.\n



Once X decides that a longer, healthier life trumps a shorter leisurely one you reach a tipping point and progress accelerates.  Humanity isn’t there yet – but you must be getting close to starting to find parts of the elixir of life.  X’s behaviour has could always be partly to blame for killing people by delaying the cures for diseases – however unless X recognises this his behaviour is unlikely to change voluntarily. \n 

Irrespective of whether or not the cure is found in time for specific individuals focussing on this is likely to make living more fun.  Saving humanity has been an enduring theme of your movies and why it shouldn’t be even better in real life is unclear. \n 


Returning to the “dismal science” what is the solution to the problem? '''

    q1 = db.question.insert(qtype="quest", questiontext=txt1, auth_userid = auth.user.id, numanswers=9,
    answers=["This is not a relevant problem for a larger planet where there are many more Xs than Ys and only some of the Ys go broke", 
    "There is no problem with concentrating wealth in practice",
    "Shared ownership of assets",
    "Equal pay for all jobs",
    "Introduce a second currency that must be earned directly",
    "Establish shared goals and objectives and monitor compliance",
    "Add good behaviour as a requirement for new life extending healthcare",
    "It is a problem but we must continue as we are",
    "Establish a global elite citizen status with privileges in return for attaching string to wealth usage"],        
        urgency=7,importance=7,category='Strategy')

    return locals()

